feat: unary operator ! support and std.not#2346
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:
📋 All resultsClick to reveal the results table (350 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
! support and std.not
There was a problem hiding this comment.
Pull request overview
Adds support for the TGSL unary ! operator during WGSL generation and introduces/extends std.not to cover vector boolean negation and numeric→boolean conversions, with accompanying tests and snapshot updates.
Changes:
- Implement TGSL unary
!codegen with compile-time folding plus runtime numeric/boolean handling. - Add/extend
std.notto support scalars and vectors (including numeric vectors) with correct WGSL emission. - Expand test coverage and update docs example snapshots affected by the new negation behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/tests/tgsl/wgslGenerator.test.ts | Adds integration tests for unary ! across comptime/runtime cases and error/warn behavior. |
| packages/typegpu/tests/std/boolean/not.test.ts | Expands std.not unit + codegen tests for scalars/vectors and error cases. |
| packages/typegpu/src/tgsl/wgslGenerator.ts | Adds unary ! operator support in the generator with runtime type handling and diagnostics. |
| packages/typegpu/src/std/boolean.ts | Redefines std.not signature/codegen and CPU implementation to support scalar + vector negation. |
| packages/typegpu/src/data/wgslTypes.ts | Adds an isBool schema guard used by std.not codegen. |
| apps/typegpu-docs/tests/individual-example-tests/tgsl-parsing-test.test.ts | Updates snapshot output impacted by negation constant-folding and new behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
iwoplaza
left a comment
There was a problem hiding this comment.
Awesome push forward! 💜🙏
|
|
||
| const f = () => { | ||
| 'use gpu'; | ||
| if (!!slot.$ && !!accessor.$) { |
There was a problem hiding this comment.
Can we use expected type or something so that there is no need to do !!? Right now there is no tgpu-side error when using non-boolean values in ifs
There was a problem hiding this comment.
Actually, we can. I'll do it.
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.96, 1.89, 3.99, 6.00, 6.23, 9.67, 20.98, 23.10]
line [0.93, 1.79, 3.88, 6.10, 6.40, 8.92, 20.55, 21.96]
line [0.86, 1.86, 3.60, 5.96, 6.44, 9.72, 20.04, 21.99]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.31, 0.51, 0.65, 0.79, 1.06, 1.20, 1.36, 1.56]
line [0.29, 0.47, 0.63, 0.80, 1.01, 1.08, 1.34, 1.53]
line [0.31, 0.47, 0.62, 0.76, 0.98, 1.09, 1.34, 1.43]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.85, 2.01, 3.35, 5.96, 12.22, 25.53, 53.25, 109.13]
line [0.85, 2.04, 3.78, 6.24, 12.29, 24.63, 52.79, 107.46]
line [0.70, 1.68, 3.09, 5.85, 11.31, 22.04, 50.24, 102.91]
|
Co-authored-by: Konrad Reczko <66403540+reczkok@users.noreply.github.com>
Changes:
std.notDifferences between them:
